home *** CD-ROM | disk | FTP | other *** search
/ HyperLib 1997 Winter - Disc 1 / HYPERLIB-1997-Winter-CD1.ISO.7z / HYPERLIB-1997-Winter-CD1.ISO / オンラインウェア / PRG / NGL2.0.1J(ppc).sit / NGL2.0.1J(ppc) / Snow Demo / Snow Demo(PPC).c < prev    next >
C/C++ Source or Header  |  1996-10-03  |  6KB  |  232 lines

  1. /*============================================================
  2.  
  3.                     Snow  デモプログラム
  4.                     
  5. ============================================================*/
  6.  
  7. #include        "N_Library.h"
  8.  
  9. void            Main_Process(void);
  10. void            Key_Process(void);
  11.  
  12. short            Data_Rsrc = 0;
  13. long                routine_step = 0;
  14. long                wait;
  15. short            S1_X[1024];
  16. short            S1_Y[1024];
  17. unsigned short        S1_D[1024];
  18. short            S1_MX[1024];
  19. short            S1_MY[1024];
  20. short            r = 0,rs=0;
  21. short            speed  = -3;
  22. Boolean            q = false;
  23. Boolean            kb=false;
  24. EventRecord        theEvent;
  25. short            Snd_List0[]     = {1000,1001,0};                //使用するサウンドリソース番号の登録
  26.  
  27. void main(void)
  28. {
  29.     WindowPtr    window;
  30.     short         i;
  31.  
  32.     ToolboxInit();
  33.     ColorCheck();
  34.     HideMenuBar();
  35.     window = GetNewWindow (128,nil,(WindowPtr)-1L );
  36.     N_Window_Set(window,-(window->portBits.bounds.left),-(window->portBits.bounds.top),640,480);
  37.     SetPort((GrafPtr)window);
  38.     N_Sp_Make(640,480);
  39.     N_Cel_Make2(640,480);
  40.  
  41.     Open_Resource_File(128,1,&Data_Rsrc);
  42. //    Set Kanban Sprites <Sprites & Cel> (Sprite 256)
  43.     Through_Col = 0xff;                                                //透明部分を黒に変更
  44.     N_Sprite_Set(200,256,216,88,0,1,1,0);                                //木の看板を登録 (Sp 256)
  45. //    Set Snow Sprites (Sprite 30-46)
  46.     N_Sprite_Set(404,30,32,32,0,1,1,2);                                //雪のパターンの登録 (Sp 30)
  47.     N_Sprite_Set(419,46,8,8,0,1,1,0);
  48.     Through_Col = 0x00;                                            //透明部分を白に変更
  49.     N_Sprite_Set(132,100,25,26,1,6,1,0);                                //Buttonの登録(Sp 100-105)
  50.     N_Sprite_Set(133,110,208,120,0,1,1,0);                            //PANELの登録(Sp 110)
  51.     N_Pict_Draw(131,0,0,(GrafPtr)SP_off,true);                            //背景は、スプライトオフスクリーンに書いておく
  52.     N_Sound_Load(&Snd_List0[0]);                                        //Buttonのオン・オフ時の音を読み込む
  53.  
  54. //    Button Set-up
  55.     N_Button_Set(0,0,1,10,404,512,0x80000000+100,0x80000000+101,1000,1001);    //Q Button
  56.     N_Button_Set(0,1,1,40,404,512,0x80000000+102,0x80000000+103,1000,1001);    //C Button
  57.     N_Button_Set(0,2,1,130,364,40,0x80000000+104,0x80000000+105,1000,1001);    //up Button
  58.     N_Button_Set(0,3,1,130,442,40,0x80000000+104,0x80000000+105,1000,1001);    //down Button
  59.     N_Button_Set(0,4,1,93,404,40,0x80000000+104,0x80000000+105,1000,1001);    //left Button
  60.     N_Button_Set(0,5,1,167,404,40,0x80000000+104,0x80000000+105,1000,1001);    //right Button
  61.  
  62.     Close_Resource_File(&Data_Rsrc);
  63.  
  64.     routine_step = 0;
  65.     for (i = 0;i!=1024;i++)
  66.     {
  67.         N_Cel_Kill(i);                                                //プレーンを初期化
  68.         S1_X[i] = GetRandom(0,640*32)-640*16;                        //配列にランダムで雪の座標を入れておく
  69.         S1_Y[i] = GetRandom(0,480*32)-480*16;
  70.         S1_D[i] = GetRandom(1,255);                                    //奥行き(大きいほど奥になる)
  71.         S1_MX[i] = GetRandom(0,30)-15;
  72.         S1_MY[i] = GetRandom(0,30)-15;
  73.     }
  74.  
  75.     N_Pict_Effect (131,0,0,3,0,0);
  76.     for (i=0;i!=32;i++)
  77.     {
  78.         Delay(1,&wait);
  79.         N_Pict_Effect (131,0,0,3,1,0);
  80.         N_Pict_Effect (131,0,0,3,1,0);
  81.         N_Pict_Effect (131,0,0,3,1,0);
  82.         N_Pict_Effect (131,0,0,3,1,0);
  83.         N_Pict_Effect (131,0,0,3,1,0);
  84.         N_Pict_Effect (131,0,0,3,1,0);
  85.         N_Pict_Effect (131,0,0,3,1,0);
  86.         N_Pict_Effect (131,0,0,3,1,0);
  87.     }
  88.     N_Button_Put(0);
  89.  
  90.     do
  91.     {
  92.         Main_Process();
  93.     }
  94.     while (q==false);
  95.     N_Sound_Close();                                                //サウンドチャネルを閉じる
  96.     FlushEvents( everyEvent, 0 ); 
  97.     ShowMenuBar();
  98.     ColorRevert();
  99.  
  100. }
  101.  
  102. void Main_Process(void)
  103. {
  104.     short            i,x,y,ii,p = 0,dist,bt;
  105.     long                wrk;
  106.     long                xx,yy;
  107.     unsigned long        dum;
  108.     char                key;
  109.     Boolean            emp;
  110.     Point                mp;
  111.  
  112.     N_Cel_Put(1800,0x80000000+110,4,356);                            //PANEL
  113.     
  114.     Key_Process();
  115.     routine_step++;
  116.     
  117.     if (routine_step<64)
  118.     {
  119.         N_Cel_Put(1799,0x80000000+256,212,(short)(routine_step*4-92));
  120.     }
  121.     if (routine_step>=64 && routine_step<192)
  122.     {
  123.         N_Cel_Put(1799,0x80000000+256,212,164);
  124.     }        
  125.     if (routine_step>=192 && routine_step <300)
  126.     {
  127.         N_Cel_Put(1799,0x80000000+256,212,(short)164+((routine_step-192)*5));
  128.     }
  129.  
  130.     if (routine_step < 700) ii = routine_step;
  131.         else    ii = 700;
  132.  
  133.     for (i = 0;i!=ii;i++)
  134.     {
  135.         S1_X[i] += S1_MX[i]+GetRandom(0,10)-5;
  136.         if (S1_X[i]<-640*16)S1_X[i]=640*16;
  137.         if (S1_X[i]>640*16)S1_X[i]=-640*16;
  138.         S1_Y[i] += S1_MY[i]+GetRandom(0,10)-5;
  139.         if (S1_Y[i]<-640*16)S1_Y[i]=640*16;
  140.         if (S1_Y[i]>640*16)S1_Y[i]=-640*16;
  141.  
  142.         x = S1_X[i];
  143.         y = S1_Y[i];
  144.  
  145.         wrk = S1_D[i];
  146.         wrk = wrk / 16;
  147.         wrk = 16-wrk;
  148.  
  149.         if (wrk>14) wrk = 15;
  150.  
  151.         N_Cel_3D_Put(i,0x80000000+30+wrk,x,y,320,240,r,S1_D[i]);        //雪の表示
  152.         dist = S1_D[i] + speed;
  153.         if (dist <  0)                                                //雪が着地するパターンを書いて、新たに雪を作成
  154.         {
  155.             dist = 512+dist;
  156.             N_Cel_Get(i,&emp,&dum,&x,&y);
  157.             N_Sp_Put(0x80000000+46,x-4,y-4);                        //雪の着地パターンは背景に直接書いて重ねる
  158.             S1_X[i] = GetRandom(0,640*32)-640*16;                    //配列にランダムで雪の座標を入れておく
  159.             S1_Y[i] = GetRandom(0,480*32)-480*16;
  160.         }            
  161.  
  162.         if (dist > 255)                                                //雪が着地するパターンを書いて、新たに雪を作成
  163.         {
  164.             dist = dist -256;            
  165.             S1_X[i] = GetRandom(0,640*32)-640*16;                    //配列にランダムで雪の座標を入れておく
  166.             S1_Y[i] = GetRandom(0,480*32)-480*16;
  167.         }            
  168.         S1_D[i] = dist;
  169.     }
  170.     r=r+rs;
  171.     N_Cel_Loop2(0,0);                                                //セル表示のすべての処理をこれを呼ぶだけで完了する
  172.  
  173.     bt=N_Button_Check(0);
  174.  
  175.     if (bt==0) q=true;
  176.     if (bt==1) N_Pict_Draw(131,0,0,(GrafPtr)SP_off,true);                    //背景を書き直す
  177.     if (bt==2)    speed--;
  178.     if (bt==3)    speed++;
  179.     if (bt==4)    rs--;
  180.     if (bt==5)    rs++;
  181. }
  182.  
  183. void Key_Process(void)
  184. {
  185.     char        ky;
  186.     
  187.     ky = N_Key_Get();
  188.     if (kb == false)
  189.     {
  190.         if ((ky & 0x01) !=0)
  191.         {
  192.             speed++;
  193.             N_Button_Push(0,3);
  194.             kb = true;
  195.         }    
  196.         if ((ky & 0x02) !=0)
  197.         {
  198.             rs--;
  199.             N_Button_Push(0,4);
  200.             kb = true;
  201.         }
  202.         if ((ky & 0x04) !=0)
  203.         {
  204.             rs++;
  205.             N_Button_Push(0,5);
  206.             kb = true;
  207.         }
  208.         if ((ky & 0x08) !=0)
  209.         {
  210.             speed--;
  211.             N_Button_Push(0,2);
  212.             kb = true;
  213.         }
  214.  
  215.         if ((ky & 0x40) !=0)
  216.         {
  217.             N_Pict_Draw(131,0,0,(GrafPtr)SP_off,true);                    //背景を書き直す
  218.             N_Button_Push(0,1);
  219.             kb = true;
  220.         }
  221.     }    
  222.  
  223.     if ((ky & 0x80) !=0)
  224.     {
  225.         N_Button_Push(0,0);
  226.          q = true;
  227.     }
  228.     if (ky==0) kb = 0;
  229. }
  230.  
  231.  
  232.